//
//  BaseChartView.h
//  ChartRefactor
//
//  Created by CaoJun on 15/3/13.
//  Copyright (c) 2015年 CaoJun. All rights reserved.
//

#import "Quotation.h"
#import "AVGData.h"
#import "KLineData.h"
#import "IndexData.h"

#import "Rectangle.h"
#import "ViewModelIndexPosition.h"

#import "PainterView.h"
#import "PainterCrosshairsView.h"
#import "PainterTextView.h"
#import "PainterUserAVGView.h"
#import "PainterUserView.h"

#import "PainterBase.h"
#import "PainterRect.h"
#import "PainterRectAVG.h"
#import "PainterRectKDJ.h"
#import "PainterKLine.h"
#import "PainterCrosshairs.h"
#import "PainterCrosshairsAVG.h"
#import "PainterText.h"
#import "PainterTextAVG.h"
#import "PainterTextKLine.h"
#import "PainterTextVolume.h"
#import "PainterTextTuov.h"
#import "PainterTextKDJ.h"
#import "PainterTextIndexPercent.h"

#import "PainterUserAVGData.h"
#import "PainterUserKLineData.h"

#import "PainterLine.h"
#import "PainterLineAVG.h"
#import "PainterLineIndex.h"

#import "PainterIndexTJ.h"
#import "PainterIndexMACD.h"
#import "PainterIndexVolume.h"
#import "PainterIndexTuov.h"
#import "PainterIndexQK.h"
#import "PainterIndexQKT.h"
#import "PainterIndexGameMatrix.h"
#import "PainterTextKLineGameMatrix.h"
#import "PainterIndexHJJT.h"
#import "PainterUserAVG.h"

#import <UIKit/UIKit.h>

static const CGFloat MinimumPressDuration = .4;

@protocol BaseChartViewDelegate;

typedef NS_ENUM(NSUInteger, BaseChartPanDirection) {
    BaseChartPanDirectionNone,
    BaseChartPanDirectionUp,
    BaseChartPanDirectionLeft,
    BaseChartPanDirectionDown,
    BaseChartPanDirectionRight
};


@interface BaseChartView : UIView

@property (nonatomic, assign) ytx::AVGData * avgData;

@property (nonatomic, assign) ytx::KLineData * kLineData;

@property (nonatomic, assign) ytx::IndexData * indexData;

@property (nonatomic, assign) ytx::ViewModelIndexPosition * indexPosition;


@property (nonatomic, strong) PainterView * rectPainterView;

@property (nonatomic, strong) PainterView * kLinePainterView;

@property (nonatomic, strong) PainterView * linePainterView;

@property (nonatomic, strong) PainterView * indexPainterView;

@property (nonatomic, strong) PainterTextView * textPainterView;

@property (nonatomic, strong) PainterCrosshairsView * crosshairsPainterView;

@property (nonatomic, strong) PainterUserAVGView * userAVGPainterView;

@property (nonatomic, strong) PainterUserView * userPainterView;

@property (nonatomic, assign) id<BaseChartViewDelegate> delegate;

@property (nonatomic, strong) UIPanGestureRecognizer * uiPanGestureRecognizer;

- (void) render;

- (void) paint;

- (BOOL) hasData;

- (void) clear;

- (void) resize;

- (void) drawCrosshairsWithX:(NSNumber *) dx withY:(NSNumber *) dy;
- (void) drawCrosshairsWithX:(NSNumber *) dx withY:(NSNumber *) dy isDrawBottomText:(BOOL) isBottomText;
- (void) drawCrosshairsWithX:(NSNumber *) dx;
- (void) clearCrosshairs;

- (void) drawTopSideTextWithX:(CGFloat) dx;
- (void) resetTopSideText;

- (void)addPanGesture;
- (void)removePanGesture;

- (void) handleLongPress:(UILongPressGestureRecognizer *)gestureRecognizer;
- (void) longPressBegin:(NSNumber *) dx;
- (void) longPressChanged:(NSNumber *) dx;
- (void) longPressCancelledOrEnded;

- (void) handlerPan:(UIPanGestureRecognizer *)gesture;
- (void) panBegin:(UIPanGestureRecognizer *)gesture;
- (void) panChanged:(UIPanGestureRecognizer *)gesture;
- (void) panCancelledOrEnded:(UIPanGestureRecognizer *)gesture;

- (void) handlePinch:(UIPinchGestureRecognizer *)gesture;
- (void) pinchBegin:(UIPinchGestureRecognizer *)gesture;
- (void) pinchChanged:(UIPinchGestureRecognizer *)gesture;
- (void) pinchCancelledOrEnded:(UIPinchGestureRecognizer *)gesture;


- (void) constructor;

- (BOOL) injectWithKey:(NSString *)key painterBaseView:(PainterView *) painterView painterBase:(PainterBase *) painterBase;
- (BOOL) injectWithKey:(NSString *)key painterBaseView:(PainterView *) painterView painterBase:(PainterBase *) painterBase atIndex:(NSUInteger) index;
- (BOOL) disinjectWithKey:(NSString *)key;

@end




@protocol BaseChartViewDelegate <NSObject>

@required

@optional
- (void) longPressBegin:(id)sender withX:(NSNumber * ) dx withY:(NSNumber * ) dy;
- (void) longPressChanged:(id)sender withX:(NSNumber * ) dx withY:(NSNumber * ) dy;
- (void) longPressCancelledOrEnded:(id)sender;
- (BOOL)chartView:(BaseChartView *)chartView longPressGestureRecognizer:(UILongPressGestureRecognizer *)longPressGestureRecognizer shouldReceiveTouch:(UITouch *)touch;

- (BOOL) pinchBegin:(id)sender withScale:(CGFloat) scale withGesture:(UIPinchGestureRecognizer *)gesture;
- (BOOL) pinchChanged:(id)sender withScale:(CGFloat) scale withGesture:(UIPinchGestureRecognizer *)gesture;
- (BOOL) pinchCancelledOrEnded:(id)sender withGesture:(UIPinchGestureRecognizer *)gesture;
- (BOOL)chartView:(BaseChartView *)chartView pinchGestureRecognizer:(UIPinchGestureRecognizer *)pinchGestureRecognizer shouldReceiveTouch:(UITouch *)touch;

- (BOOL) panBegin:(id)sender withGesture:(UIPanGestureRecognizer *)gesture;
- (BOOL) panChanged:(id)sender withGesture:(UIPanGestureRecognizer *)gesture;
- (BOOL) panCancelledOrEnded:(id)sender withGesture:(UIPanGestureRecognizer *)gesture;
- (BOOL)chartView:(BaseChartView *)chartView panGestureRecognizer:(UIPanGestureRecognizer *)panGestureRecognizer shouldReceiveTouch:(UITouch *)touch;
- (void) panDirection:(BaseChartPanDirection)direction;

@end

